package Dict;

/** 
 * Helper class for : PropertyType
 *  
 * @author OpenORB Compiler
 */ 
public class PropertyTypeHelper
{
    private static final boolean HAS_OPENORB;
    static
    {
        boolean hasOpenORB = false;
        try
        {
            Thread.currentThread().getContextClassLoader().loadClass( "org.openorb.orb.core.Any" );
            hasOpenORB = true;
        }
        catch ( ClassNotFoundException ex )
        {
            // do nothing
        }
        HAS_OPENORB = hasOpenORB;
    }
    /**
     * Insert PropertyType into an any
     * @param a an any
     * @param t PropertyType value
     */
    public static void insert(org.omg.CORBA.Any a, Dict.PropertyType t)
    {
        a.insert_Streamable(new Dict.PropertyTypeHolder(t));
    }

    /**
     * Extract PropertyType from an any
     *
     * @param a an any
     * @return the extracted PropertyType value
     */
    public static Dict.PropertyType extract( org.omg.CORBA.Any a )
    {
        if ( !a.type().equivalent( type() ) )
        {
            throw new org.omg.CORBA.MARSHAL();
        }
        if (HAS_OPENORB && a instanceof org.openorb.orb.core.Any) {
            // streamable extraction. The jdk stubs incorrectly define the Any stub
            org.openorb.orb.core.Any any = (org.openorb.orb.core.Any)a;
            try {
                org.omg.CORBA.portable.Streamable s = any.extract_Streamable();
                if ( s instanceof Dict.PropertyTypeHolder )
                    return ( ( Dict.PropertyTypeHolder ) s ).value;
            }
            catch ( org.omg.CORBA.BAD_INV_ORDER ex )
            {
            }
            Dict.PropertyTypeHolder h = new Dict.PropertyTypeHolder( read( a.create_input_stream() ) );
            a.insert_Streamable( h );
            return h.value;
        }
        return read( a.create_input_stream() );
    }

    //
    // Internal TypeCode value
    //
    private static org.omg.CORBA.TypeCode _tc = null;
    private static boolean _working = false;

    /**
     * Return the PropertyType TypeCode
     * @return a TypeCode
     */
    public static org.omg.CORBA.TypeCode type()
    {
        if (_tc == null) {
            synchronized(org.omg.CORBA.TypeCode.class) {
                if (_tc != null)
                    return _tc;
                if (_working)
                    return org.omg.CORBA.ORB.init().create_recursive_tc(id());
                _working = true;
                org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init();
                org.omg.CORBA.UnionMember _members[] = new org.omg.CORBA.UnionMember[ 3 ];
                org.omg.CORBA.Any any;

                any = orb.create_any();
                Dict.CategoryValueHelper.insert( any,Dict.CategoryValue.NOM );
                _members[ 0 ] = new org.omg.CORBA.UnionMember();
                _members[ 0 ].name = "pNom";
                _members[ 0 ].label = any;
                _members[ 0 ].type = Dict.PropNomHelper.type();
                any = orb.create_any();
                Dict.CategoryValueHelper.insert( any,Dict.CategoryValue.ADJ );
                _members[ 1 ] = new org.omg.CORBA.UnionMember();
                _members[ 1 ].name = "pAdj";
                _members[ 1 ].label = any;
                _members[ 1 ].type = Dict.PropAdjHelper.type();
                any = orb.create_any();
                Dict.CategoryValueHelper.insert( any,Dict.CategoryValue.VER );
                _members[ 2 ] = new org.omg.CORBA.UnionMember();
                _members[ 2 ].name = "pVer";
                _members[ 2 ].label = any;
                _members[ 2 ].type = Dict.PropVerHelper.type();
                _tc = orb.create_union_tc( id(), "PropertyType", Dict.CategoryValueHelper.type(), _members );
                _working = false;
            }
        }
        return _tc;
    }

    /**
     * Return the PropertyType IDL ID
     * @return an ID
     */
    public static String id()
    {
        return _id;
    }

    private final static String _id = "IDL:Dict/PropertyType:1.0";

    /**
     * Read PropertyType from a marshalled stream
     * @param istream the input stream
     * @return the readed PropertyType value
     */
    public static Dict.PropertyType read(org.omg.CORBA.portable.InputStream istream)
    {
        Dict.PropertyType new_one = new Dict.PropertyType();

        new_one.__d = Dict.CategoryValueHelper.read(istream);
        if (new_one.__d.value() == Dict.CategoryValue._NOM)
        {
            new_one._pNom = Dict.PropNomHelper.read(istream);
        }
        else
        if (new_one.__d.value() == Dict.CategoryValue._ADJ)
        {
            new_one._pAdj = Dict.PropAdjHelper.read(istream);
        }
        else
        if (new_one.__d.value() == Dict.CategoryValue._VER)
        {
            new_one._pVer = Dict.PropVerHelper.read(istream);
        }

        return new_one;
    }

    /**
     * Write PropertyType into a marshalled stream
     * @param ostream the output stream
     * @param value PropertyType value
     */
    public static void write(org.omg.CORBA.portable.OutputStream ostream, Dict.PropertyType value)
    {
        Dict.CategoryValueHelper.write( ostream, value.__d );
        if (value.__d.value() == Dict.CategoryValue._NOM)
        {
            Dict.PropNomHelper.write( ostream, value._pNom );
        }
        else
        if (value.__d.value() == Dict.CategoryValue._ADJ)
        {
            Dict.PropAdjHelper.write( ostream, value._pAdj );
        }
        else
        if (value.__d.value() == Dict.CategoryValue._VER)
        {
            Dict.PropVerHelper.write( ostream, value._pVer );
        }
    }

}
